#include "SQLPartitionByValue.h"
#include "../../sql/ast/SQLPartition.h"
#include "../../sql/visitor/SQLASTVisitor.h"
#include "../../utils/listTran.h"
#include "../../utils/log.h"
#include "SQLSubPartitionBy.h"

// @Override
void SQLPartitionByValue::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLPartitionByValue)))
  {
    SQLObject_list_ptr  tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(columns);
    acceptChild(visitor, tmp1);
    SQLObject_list_ptr  tmp3 = ListTran::tran_class<SQLName, SQLObject>(storeIn);
    acceptChild(visitor, tmp3);
    SQLObject_list_ptr  tmp4 = ListTran::tran_class<SQLPartition, SQLObject>(partitions);
    acceptChild(visitor, tmp4);
    acceptChild(visitor, SQLSubPartitionBy_ptr(subPartitionBy));
  }
  visitor->endVisit(SharedObject(SQLPartitionByValue));
}

SQLObject_ptr SQLPartitionByValue::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLPartitionByValue>(new SQLPartitionByValue());
  std::shared_ptr<SQLPartitionByValue> x = std::dynamic_pointer_cast<SQLPartitionByValue>(clone_tmp);
  // SQLPartitionByValue *x = new SQLPartitionByValue();

  cloneTo(x);

  for (SQLExpr_ptr column : *columns)
  {
    SQLExpr_ptr c2 = std::dynamic_pointer_cast<SQLExpr>(column->clone());
    c2->setParent(x);
    x->columns->push_back(c2);
  }

  return x;
}

void SQLPartitionByValue::cloneTo(SQLPartitionByValue_ptr x)
{
  SQLPartitionBy::cloneTo(x);
}
